﻿using JESAI.Application.Abstractions.Admin.Dtos.Dict;
using JESAI.Application.Abstractions.Admin;
using JESAI.Application.Abstractions.Dtos;
using JESAI.Application.Abstractions.DynamicApi;
using JESAI.Framework.Filters;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using JESAI.Application.Abstractions.DynamicApi.Dtos;
using JESAI.Platform.WebApi.Vos.DynamicApi;
using JESAI.AutoMapper.ObjectMapping;
using JESAI.MonacoRoslynComplete.Models;

namespace JESAI.Platform.WebApi.Controllers.DynamicApi
{
    [ApiController]
    [Route("api/v1/[controller]")]
    [Authorize("permission")]
    [IgnoreResultHandlerAttribute]
    public class DynamicApiController : ControllerBase
    {
        private readonly IDynamicApiService _dynamicApiService;

        public DynamicApiController(IDynamicApiService dynamicApiService)
        {
            _dynamicApiService = dynamicApiService;
        }

        [HttpPost("SetDynamicApi")]
        public async Task<BaseOutput> SetDynamicApi([FromBody] DynamicApiInput input)
        {
            await _dynamicApiService.SetDynamicApi(input);
            return new BaseOutput();
        }

        /// <summary>
        /// 删除字典
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpGet("DeleteDynamicApis")]
        public async Task<BaseOutput> DeleteDynamicApis(string[] ids)
        {
            await _dynamicApiService.DeleteDynamicApis(ids);
            return new BaseOutput { };
        }

        [HttpGet("DeleteDynamicApi")]
        public async Task<BaseOutput> DeleteDynamicApi(string id)
        {
            await _dynamicApiService.DeleteDynamicApi(id);
            return new BaseOutput { };
        }

        /// <summary>
        /// 查询字典列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("QueryPageDynamicApis")]
        public async Task<BasePageOutput<List<DynamicApiResponse>>> QueryPageDynamicApis([FromQuery] QueryDynamicApiPageParam param)
        {
            var result = await _dynamicApiService.QueryPageDynamicApis(param);
            return result.MapTo<BasePageOutput<List<DynamicApiResponse>>>();
        }

        [HttpGet("QueryScriptCodeFileList")]
        public async Task<BaseOutput<List<ICodeFileModel>>> QueryScriptCodeFileList()
        {
            var result = await _dynamicApiService.QueryScriptCodeFileList();
            return new BaseOutput<List<ICodeFileModel>> { Data = result };
        }

    }
}
